ChangeManager = null;

_ChangeManager = function() {
 }
_ChangeManager.prototype = {
Change: function(Login, Password1,Password2,FirstName,MiddleName,SecondName,Gender,Age) {

		var _ChangeUser = ClientCommandsManager.Get("EditUserClientCommand");
		_ChangeUser.Login = FieldManager.Login;
		
		if(Password1 != Password2)
		{
			var nItem = NotificationManager.CreateNotification("Password and password confirmation don't coincide", ["error"]);
			NotificationManager.ShowMessages([nItem]);
			return;
		}
		
		if(!(ValidationController.CreateAndAddValidationItemToStack(Password1, isNullOrEmpty).ValidateAndCleanStack().Result))
		{
			_ChangeUser.Password = $.md5(Password1);
		}
		if(!(ValidationController.CreateAndAddValidationItemToStack(FirstName, isNullOrEmpty).ValidateAndCleanStack().Result))
		{
			_ChangeUser.FirstName = FirstName;
		}
		if(!(ValidationController.CreateAndAddValidationItemToStack(MiddleName, isNullOrEmpty).ValidateAndCleanStack().Result))
		{
			_ChangeUser.MiddleName = MiddleName;
		}
		if(!(ValidationController.CreateAndAddValidationItemToStack(SecondName, isNullOrEmpty).ValidateAndCleanStack().Result))
		{
			_ChangeUser.SecondName = SecondName;
		}
		if((ValidationController.CreateAndAddValidationItemToStack(Gender, isNullOrEmpty).ValidateAndCleanStack().Result))
		{
			_ChangeUser.Gender = FieldManager.Gender;
		}
		else 
		{
			_ChangeUser.Gender = Gender;
		}
		if(!(ValidationController.CreateAndAddValidationItemToStack(Age, isNullOrEmpty).ValidateAndCleanStack().Result))
		{
			_ChangeUser.Age = Age;
		}
		CloakManager.OnCloak(false,true);
	    ClientCommandsManager.Execute(_ChangeUser, this.SuccessHandler, null);
	},
	SuccessHandler: function(data, status, request) {
		CloakManager.OffCloak(true,true);
		if(data){
			var nItem = NotificationManager.CreateNotification("User " + FieldManager.Login + " has been Change", ["ok"]);
    		NotificationManager.ShowMessages([nItem]);
		}
		else{
			var nItem = NotificationManager.CreateNotification("Error. User with such login don't exist", ["error"]);
    		NotificationManager.ShowMessages([nItem]);
		}
    }
}